#include <stdio.h>
#include <stdlib.h>
#include "disks.h"
#include "consts.h"

public dev device_list[N_DEV];

tword get_device_no(int dev_no)
{
    return (tword)0x7fffffff;
}

int read_block(int dev_no, dword block_no, byte *buffer_in)
{
    dev* d= &device_list[dev_no];
    FILE* fp;
    
    if ( d->dev_type != block_device)
        panic("Read Block Error: wrong device");
        
    fp = fopen( d->dev_description, "r");
    fseek(fp, BLOCK_SIZE*block_no, SEEK_SET);
    fread(buffer_in, sizeof(byte), BLOCK_SIZE, fp);
    fclose(fp);

    return 1;
}

int write_block(int dev_no, dword block_no, byte *buffer_out)
{
    dev* d=&device_list[dev_no];
    FILE* fp;

    if ( d->dev_type != block_device )
        panic("Write Block Error: wrong device");

    fp = fopen( d->dev_description, "w+");
    fseek(fp, BLOCK_SIZE*block_no, SEEK_SET);
    fwrite(buffer_out, sizeof(byte), BLOCK_SIZE, fp);

    return 1;
}

